package ee.ut.aa.neuraltic.logic;

import java.util.List;

import org.apache.log4j.Logger;

import ee.ut.aa.neuraltic.neural.Layer;
import ee.ut.aa.neuraltic.neural.Network;
import ee.ut.aa.neuraltic.neural.Neuron;
import ee.ut.aa.neuraltic.neural.Synaps;

public class PopulationStats {

	private static Logger log = Logger.getLogger( PopulationStats.class );

	public static void logNetwork( Network network ) {

		Logger netlog = Logger.getLogger( "networks" );

		if( !netlog.isDebugEnabled() )
			return;

		String result = "Network value=" + network.getValue();

		for( Layer layer : network.getLayers() ) {
			result += "\n[";
			for( Neuron neuron : layer.getNeurons() ) {
				result += "  \n[";
				for( Synaps synaps : neuron.getSynapses() ) {
					result += "[" + synaps.getWeight() + "];";
				}
				result += "]";
			}
			result += "]";
		}

		netlog.debug( result );
	}

	public static void logStats( List<Network> population ) {

		int min = Integer.MAX_VALUE;
		int avg = 0;
		int max = Integer.MIN_VALUE;

		int tmp;

		for( Network network : population ) {
			tmp = network.getValue();

			min = tmp < min ? tmp : min;
			avg += tmp;
			max = tmp > max ? tmp : max;
		}

		avg = avg / population.size();

		log.info( "Population stats;min=" + min + ";avg=" + avg + ";max=" + max );
	}
}
